/*
 * Copyright 2021 DataCanvas
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.dingodb.common.sequence;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@Setter
@Getter
@NoArgsConstructor
@ToString
public class SequenceDefinition {

    private String name;
    private int increment;
    private long minvalue;
    private long maxvalue;
    private long start;
    private int cache;
    private boolean cycle;

    public SequenceDefinition(String name,
                              int increment,
                              long minvalue,
                              long maxvalue,
                              long start,
                              int cache,
                              boolean cycle) {
        if (maxvalue == -1) {
            throw new IllegalArgumentException("maxvalue cannot be null.");
        }
        if (minvalue > maxvalue) {
            throw new IllegalArgumentException("minvalue cannot be greater than maxvalue.");
        }
        if (start < minvalue || start > maxvalue) {
            throw new IllegalArgumentException("startValue must be within the range of minvalue and maxvalue");
        }
        this.name = name;
        this.increment = increment;
        this.minvalue = minvalue;
        this.maxvalue = maxvalue;
        this.start = start;
        this.cache = cache;
        this.cycle = cycle;
    }
}
